//****************************************************************
//  PP12_9.java   Author: 唐才铭
//
//  演示输出杨辉三角的某一行。
//****************************************************************
import java.util.*;

public class PP12_9 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入选择输出杨辉三角的第N行：");
        int N = scanner.nextInt();

        String a="",line="";
        String[] b = new String[0];
        List lines = new LinkedList();

        for (int i = 1;i<=N;i++)
        {
            for (int k = 1;k<=i;k++)
            {
                a += Pascal(i,k)+ " ";
                b = a.split("1 1");
            }
            if (i==1)
                line = b[0];
            else
                for (int j = 0;j<i;j++)
                {
                    line ="1" + b[j]  ;
                }
            lines.add(line);
        }
        String[] intArray = (String[])  lines.toArray(new String[0]);
        System.out.println("前" + N + "行杨辉三角如下：");
        for (int f = 0;f<N;f++)
        {
            System.out.println( "第" + (f+1) + "行:" + intArray[f]);
        }
        System.out.println("杨辉三角的第" + N +"行为:" + intArray[N-1]);


    }
    static int Pascal(int rows,int columns)   //  rows:行数；columns列数
    {
        if (columns==1||rows==columns)
            return 1;
        else
            return Pascal(rows-1,columns-1) + Pascal(rows-1,columns);
    }
}
